<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/psysCommon.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>角色管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span
        class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
    <div class="text-c">
        <input type="text" class="input-text" style="width:250px" placeholder="请输入权限名称" id="modelname" name="modelname">
        <button type="submit" class="btn btn-success" id="search" name=""><i class="icon-search"></i> 搜权限</button>

    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
    <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="icon-trash"></i> 批量删除</a>
    <a href="javascript:;" onclick="user_add('550','','添加权限','permission-add.html')" class="btn btn-primary radius"><i
            class="icon-plus"></i> 添加权限</a></span>
        <!--        <span class="r">共有数据：<strong>88</strong> 条</span>-->
    </div>
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
        <tr class="text-c">
            <th width="5%"><input type="checkbox" name="" value=""></th>
            <th width="50%">权限名称</th>
            <th width="45%">权限标识</th>
        </tr>
        </thead>
        <tbody id="data">
        </tbody>
    </table>
    <table>
        <tr>
            <td>
                <div style="height: 7px"></div>
            </td>
        </tr>
    </table>
    <table width="97%" border="0" cellspacing="0" cellpadding="0" height="50">
        <tr>
            <input type="text" id="up" style="display:none;"/>
            <input type="text" id="down" style="display:none;"/>
            <input type="text" id="end" style="display:none;"/>
            <td align="center">
                <div class="pagination">
                    <span title="首页" id="index">首页</span>
                    <span title="上一页" id="upclick">上一页</span>
                    <span title="下一页" id="dowmclick">下一页</span>
                    <span id="endclick">尾页</span>
                    第&nbsp;<span id="curPage"></span>&nbsp;页/共&nbsp;<span id="totalPage"></span>页
                </div>
            </td>
        </tr>
    </table>
    <div id="pageNav" class="pageNav"></div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    window.onload = (function () {
        loadlist();

        $("#search").click(function () {
            loadlist(JSON.stringify(searchData()));
        })
        //分页按钮
        $("#index").click(function (e) {
            loadlist(JSON.stringify(searchData()), 1);
        });
        $("#upclick").click(function (e) {
            var up = $("#up").val();
            loadlist(JSON.stringify(searchData()), up);
        });
        $("#dowmclick").click(function (e) {
            var down = $("#down").val();
            loadlist(JSON.stringify(searchData()), down);
        });
        $("#endclick,#totalPage").click(function (e) {
            var end = $("#end").val();
            loadlist(JSON.stringify(searchData()), end);
        });
    });
    $('.table-sort').dataTable({
        "lengthMenu": false,//显示数量选择
        "bFilter": false,//过滤功能
        "bPaginate": false,//翻页信息
        "bInfo": false,//数量信息
        "aaSorting": [[1, "desc"]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable": false, "aTargets": [0, 8, 9]}// 制定列不参与排序
        ]
    });

    function user_show(pid) {
        // alert(userid);
        var url = "permission-add.html?pid=" + pid;                             //转向网页的地址;
        var name = 'add';                            //网页名称，可为空;
        var iWidth = 720;                          //弹出窗口的宽度;
        var iHeight = 600;                         //弹出窗口的高度;
        //获得窗口的垂直位置
        var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
        //获得窗口的水平位置
        var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
        window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
        // window.open("user-add.html", "_blank", "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes");
    }

    function user_add() {
        var url = "permission-add.html";                             //转向网页的地址;
        var name = 'add';                            //网页名称，可为空;
        var iWidth = 720;                          //弹出窗口的宽度;
        var iHeight = 600;                         //弹出窗口的高度;
        //获得窗口的垂直位置
        var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
        //获得窗口的水平位置
        var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
        window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
        // window.open("user-add.html", "_blank", "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes");
    }

    function loadlist(serachData,page) {
        $.ajax({
            type: 'POST',
            url: '/permission/list',
            dataType: 'json',
            data: {paramData: serachData, page: page},
            success: function (data) {
                var html;
                if (data.code == 200) {
                    var resData = data.data.records;
                    for (var x = 0; x < resData.length; x++) {
                        html = html + " <tr class=\"text-c\">";
                        html = html + "<td><input type=\"checkbox\" value=\"1\" name=\"\"></td>";
                        html = html + "<td style=\"display:none\">" + resData[x].pid + "</td>";
                        html = html + "<td><u style=\"cursor:pointer\" class=\"text-primary\" onclick=\"user_show( '" + resData[x].pid + "')\">" + resData[x].modelname + "</u></td>";
                        html = html + " <td>" + resData[x].permission + "</td>";
                        html = html + " </tr>";
                    }
                    $("#data").empty();
                    $("#data").append(html);
                    //分页参数
                    $("#curPage").html(data.data.current);
                    $("#totalPage").html(data.data.pages);

                    $("#up").val(data.data.current == 1 ? data.data.current : data.data.current - 1);
                    $("#down").val(data.data.current == data.data.pages ? data.data.current : data.data.current + 1);
                    $("#end").val(data.data.pages);
                }
            }
        })
    }

    function datadel() {
        var idList = [];
        $("#data").find(":checkbox:checked").each(function () {
            var value = $(this).parent().next().text();
            //  alert(value);
            idList.push(value);
        });
        //alert(JSON.stringify(idList));
        $.ajax({
            type: 'POST',
            url: '/permission/del',
            dataType: 'json',
            data: "ids=" + idList,
            success: function (data) {
                alert(data.msg);
                loadlist();
            }
        })

    }

    function searchData() {
        var modelname = $("#modelname").val();
        var jsonArray = [];
        if (modelname != null && modelname != "") {
            var obj = {'column': "modelname", 'type': 'like', "value": modelname};
            jsonArray.push(obj)
        }
        return jsonArray;
    }
</script>
</body>
</html>
